﻿using OnlineEducation.Data.Entities;
using OnlineEducation.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace OnlineEducation.Helpers
{
    public static class EntityHelper
    {

        public static void MarkAdded(this EntityBase entityBase)
        {
            if (HttpContextHelper.Current == null || HttpContextHelper.Current.User == null || HttpContextHelper.Current.User.Identity == null)
            {
                entityBase.UpdatedBy = "System";
                entityBase.CreatedBy = "System";
            }
            else
            {
                entityBase.UpdatedBy = HttpContextHelper.Current.User.Identity.Name ?? "System";
                entityBase.CreatedBy = HttpContextHelper.Current.User.Identity.Name ?? "System";
            }

            entityBase.UpdatedTime = DateTime.Now;
            entityBase.CreatedTime = DateTime.Now;


        }
        public static void MarkModified(this EntityBase entityBase)
        {
            if (HttpContextHelper.Current == null || HttpContextHelper.Current.User == null || HttpContextHelper.Current.User.Identity == null)
            {
                entityBase.UpdatedBy = "System";
                entityBase.CreatedBy = "System";
            }
            else
            {
                entityBase.UpdatedBy = HttpContextHelper.Current?.User.Identity.Name ?? "System";
            }

            entityBase.UpdatedTime = DateTime.Now;
        }
        

    }
}
